﻿package app.view.vc 
{
    import app.view.event.UIEvent;
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    
    /**
    * Author lzyy
    * Email:healdream@gmail.com
    * Blog:http://lab.lzyy.name/blog
    */
    public class NumberBtns extends MovieClip
    {
        public static const BTN_CLICKED:String = 'btn_clicked';
        public function NumberBtns() 
        {
            
        }
        
        public function addBtn(n)
        {
            for (var i = 0; i < n; i++)
            {
                var btn:MovieClip = new NumberBtn();
                btn.i = i;
                btn.name = 'btn' + i;
                btn.numTxt.text = (i + 1).toString();
                btn.numTxt.mouseEnabled = false;
                btn.x = i * btn.width;
                btn.buttonMode = true;
                btn.addEventListener(MouseEvent.CLICK, _onBtnClick);
                addChild(btn);
            }
        }
        
        private function _onBtnClick(evt:MouseEvent)
        {
            var dest = MovieClip(evt.currentTarget);
            dispatchEvent(new UIEvent(BTN_CLICKED, {index:dest.i}));
        }
        
    }
    
}